package org.exaple.mp.plugins;

import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import lombok.Setter;
import lombok.experimental.Accessors;
import org.apache.ibatis.executor.statement.StatementHandler;
import org.apache.ibatis.plugin.Intercepts;
import org.apache.ibatis.plugin.Invocation;
import org.apache.ibatis.plugin.Signature;
import org.exaple.mp.intercept.QueryInterceptor;

import java.sql.Connection;

/**
 * 拓展分页拦截器
 *
 */
@Setter
@Accessors(chain = true)
@Intercepts({@Signature(type = StatementHandler.class, method = "prepare", args = {Connection.class, Integer.class})})
public class CustomPaginationInterceptor extends PaginationInterceptor {

	/**
	 * 查询拦截器
	 */
	private QueryInterceptor[] queryInterceptors;

	@Override
	public Object intercept(Invocation invocation) throws Throwable {
		// 查询拦截器
		QueryInterceptorExecutor.exec(queryInterceptors, invocation);
		return super.intercept(invocation);
	}

}
